import { DEL_LIST, ADD_LIST } from './actions'
export interface IActionType {
	type: string
	payload?: any,
}

export interface IListItem {
	name: string
	age: number
	sex: '男' | '女',
	id?: number
}
export interface IStateType {
	list: IListItem[]
}

const initState: IStateType = {
	list: [{
		name: '张三',
		age: 18,
		sex: '男',
		id: 1
	}]
}

const reducer = (state: IStateType = initState, action: IActionType) => {
	switch (action.type) {
		case DEL_LIST:
			return {
				...state,
				list: state.list.filter(v => v.id !== action.payload)
			}
			case ADD_LIST:
				return {
					...state,
					list: [...state.list, action.payload]
				}
		default:
			return state
	}
}


export default reducer
